package com.brk.socket.exception;

import com.brk.socket.common.CommonResult;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletResponse;

/**
 * @author brk
 * @date 2023/7/16 16:53
 * @Description:
 */
@RestControllerAdvice
public class ExceptionHandler {

    /**
     * 捕获自定义异常
     *
     * @param e        捕获的异常
     * @param response 响应前端
     * @return 响应结果
     */
    @org.springframework.web.bind.annotation.ExceptionHandler(MyException.class)
    public CommonResult customExceptionHandler(MyException e, HttpServletResponse response) {
        response.setStatus(HttpStatus.OK.value());
        return new CommonResult(e.getErrorCode(), e.getErrorMsg(), null);
    }

}
